package com.qlc.spring.cloud.demo.user.controller;

import com.qlc.spring.cloud.demo.Result;
import com.qlc.spring.cloud.demo.user.VO.UserVO;
import com.qlc.spring.cloud.demo.user.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * Name:  UserController
 * User:  wang chang
 * CreateTime: 2019-05-28 16:02
 **/

@RestController
public class UserController {

    @Autowired
    UserService userService;

    @RequestMapping(value = "/test/net/{userCode}", method = {RequestMethod.GET})
    public Result<UserVO> getUserByCode(@PathVariable("userCode") String userCode) {

        Result<UserVO> result = new Result<UserVO>();
        UserVO userVO = userService.getUserByCode(userCode);
        if (userVO == null) {
            result.setCode("-1");
            result.setMessage("失败");
            return result;
        }
        result.setCode("0");
        result.setMessage("成功");
        result.setData(userVO);
        return result;
    }

    @RequestMapping(value = "/test/add")
    public Result<Void> addUser(@RequestBody(required = false) UserVO userVO) {
        Result<Void> result = new Result<Void>();
        boolean bl = userService.addUser(userVO);
        if (bl) {
            result.setCode("0");
            result.setMessage("成功");
            return result;
        }
        result.setCode("-1");
        result.setMessage("失败");
        return result;
    }
}
